﻿(function ($, window, document, undefined) {
	//默认参数
	var PARAMS;
	var DEFAULTPARAMS = { Title: "标题", Content: "", BtnL: "确定", BtnR: "取消", FunL: new Object, FunR: new Object };
	$.DialogByA = {
		//弹出提示框
		Alert: function (params) { Show(params, "Alert"); },
		//弹出确认框
		Confirm: function (params) { Show(params, "Confirm"); },
		//关闭弹出框
		Close: function () {
			$(".ModiftyModelShow").remove();
		},


	};
	//初始化参数
	function Init(params) {
		if (params != undefined && params != null) {
			PARAMS = $.extend({}, DEFAULTPARAMS, params);
		}
	};
	function Show(params, caller) {
		Init(params);
		var dislogContainer;
		var alertOption = GetImg(PARAMS.Content);
		var blackFilter = $('<div class="zbox-popup-backdrop" style="display: block;"></div>');
		if (caller == 'Alert') {
			dislogContainer = $('<div class="ModiftyModel">\
			<div class="check_panel">\
				<div class="bubble_top">\
					<span class="bubble_top_span1">'+ alertOption[1] + '</span>\
					<span class="check_panel_span" @click="getClose()">\
						<img style="width: 12px;height: 12px" src="image/alertImg/close.png" />\
					</span>\
				</div>\
				<div class="alertinfo"> <img src="image/alertImg/'+ alertOption[0] + '.png"\
						style="width:24px;height:24px;margin-right:10px;float:left;" /><span\
						style="font-size:14px;">' + PARAMS.Content + '</span></div>\
				<div class="check_but" style="width: 100%;text-align: right;min-height:30px;">\
				    <button type="button" class="btn check_but3" style="width: 80px" onclick="sureFun()">确 定</button>\
				</div>\
			</div>\
		</div>');
			// <button type="button" class="btn check_but1" style="width: 80px" onclick="sureFun()">确定</button>\
			// <button type="button" class="btn check_but2" onclick="getClose()" style="width: 80px">取消</button>\

			setTimeout(function () {
				$(".ModiftyModel").addClass('ModiftyModelShow');
			}, 10)
			$("body").append(dislogContainer);

		}
		else if (caller == 'Confirm') {
			dislogContainer = $('<div class="ModiftyModel">\
			<div class="check_panel">\
				<div class="bubble_top">\
					<span class="bubble_top_span1">'+ alertOption[1] + '</span>\
					<span class="check_panel_span" @click="getClose()">\
						<img style="width: 12px;height: 12px" src="image/alertImg/close.png" />\
					</span>\
				</div>\
				<div class="alertinfo"> <img src="image/alertImg/'+ alertOption[0] + '.png"\
						style="width:24px;height:24px;margin-right:10px;float:left;" /><span\
						style="font-size:14px;">' + PARAMS.Content + '</span></div>\
				<div class="check_but" style="width: 100%;text-align: center;min-height:30px;">\
				 <button type="button" class="btn check_but1" style="width: 80px" id="btnSure">确定</button>\
				 <button type="button" class="btn check_but2" onclick="getClose()" style="width: 80px">取消</button>\
				</div>\
			</div>\
		</div>');

			setTimeout(function () {
				$(".ModiftyModel").addClass('ModiftyModelShow');
			}, 10)
			$("body").append(dislogContainer);

			$("#btnSure").click(function () {
				//左侧按钮
				if ($.isFunction(PARAMS.FunL)) {
					PARAMS.FunL();
				} else {
					$.DialogByA.Close();
				}
				return true;
			})

		}
	}

})(jQuery, window, document);

function sureFun() {
	$.DialogByA.Close();
}
function getClose() {
	$.DialogByA.Close();
}
function ConfirmFun() {

}
function alert(Content) {
	$.DialogByA.Alert({ Title: "系统提示", Content: Content, BtnL: "确定" });
	$(".check_panel").bg_move({
		move: '.bubble_top',
		closed: '.close',
		size: 6
	});
}
function confirm1(Content, FunL) {
	$.DialogByA.Confirm({
		Content: Content, FunL: FunL
	})
}

function GetImg(reval) {
	var alertOption = [];
	if (Contain(reval, "success")) {
		alertOption = ["success", "成功提示"];
	}
	else if (Contain(reval, "warning")) {
		alertOption = ["warning", "警示提示"];
	}
	else if (Contain(reval, "error")) {
		alertOption = ["error", "错误提示"];
	} else {
		alertOption = ["tip", "信息提示"];
	}
	return alertOption;
}

function Contain(content, key) {
	var flag = false;
	if (key == "success") {
		var arr = ["成功", "胜利"];
		arr.forEach(function (item) {
			if (!flag) {
				flag = content.indexOf(item) > -1
			}
		})
	}
	else if (key == "warning") {
		var arr = ["不可为空", "稍后重试", "请至少", "不能", "请填写", "请输入", "请选择", "请勾选", "请绘制", "必须", "请先", "不可以", "不完整", "不允许", "有效"];
		arr.forEach(function (item) {
			if (!flag) {
				flag = content.indexOf(item) > -1
			}
		})
	}
	else if (key == "error") {
		var arr = ["失败", "重新", "错误", "已经存在", "不正确"];
		arr.forEach(function (item) {
			if (!flag) {
				flag = content.indexOf(item) > -1
			}
		})
	}
	return flag;
}